/**
 * Created by KhoaNam on 6/28/2014.
 */
var Player = cc.Class.extend({
    ctor: function(){
        //this._super();
        this.name = "User";
        this.money = 25000;
        this.position = 0 ;
        this.id = 0;
        this.avatar = "";
        this.isCurrent = false;
        this.isReady = false;

        this.nameSprite = null;
        this.avatarSprite = null;
        this.directionSprite = null;
    },

    init: function(data){
        if(data.name){
            this.name = data.name;
        }
        if(data.isCurrent){
            this.isCurrent = data.isCurrent;
        }
        if(data.position){
            this.position = data.position;
        }
        if(data.money){
            this.money = data.money;
        }
        if(data.avatar){
            this.avatar = data.avatar;
        }

        if(data.id){
            this.id = data.id;
        }

        this.isReady = false;
    },

    initWaitting: function(data){
        this.init(data);

    },

    initPlayGame: function (data) {
        this.init(data);
    },

    getNameSprite: function(){
        if(this.nameSprite == null){
            this.nameSprite = cc.LabelTTF.create(this.name, PLAYERINFO.NAME_FONT, PLAYERINFO.NAME_SIZE);
        }
        return this.nameSprite;
    },

    getAvatarSprite: function () {
        if(this.avatarSprite == null){
            var strAvatar = this.avatar.length > 0 ? this.avatar : PLAYERINFO.DEFAULT_PROFILE;
            this.avatarSprite = cc.Sprite.create(strAvatar);
        }
        return this.avatarSprite;
    },

    getDirectionSprite: function(){
        if(this.directionSprite == null){
            var strIcon = "";
            switch (this.position){
                case 1:
                    strIcon = PLAYERINFO.DIRECTION_ICON_EAST;
                    break;
                case 2:
                    strIcon = PLAYERINFO.DIRECTION_ICON_SOUTH;
                    break;
                case 3:
                    strIcon = PLAYERINFO.DIRECTION_ICON_WEST;
                    break;
                case 4:
                    strIcon = PLAYERINFO.DIRECTION_ICON_NORTH;
                    break;
            }
            this.directionSprite = cc.Sprite.create(strIcon);
        }
        return this.directionSprite;
    },

    getTextNamePosition: function(){
        var position = this.getAvatarSprite().getPosition();
        position.y  -= (this.getAvatarSprite().getContentSize().height/2 + this.getNameSprite().getContentSize().height/2);
        return position;
    },

    getDirectionIconPosition: function(){
        var position = this.getAvatarSprite().getPosition();
        position.y  += this.getDirectionSprite().getContentSize().height/2 + this.getAvatarSprite().getContentSize().height/2 - 5;
        return position;
    },

    addTile: function (tile) {
        if(this.tiles.current.length == 0){

        }
        else{

        }
    },

    addTileWithAnimation: function (tile) {

    },

    doTile: function(tile){

    }
});